<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 17-11-2
 * Time: 下午4:35
 */
namespace CloudHash;

class Client{
    public static $host;
    public static $port;

    public static function get($key){
        return self::request("GET {$key}");
    }

    public static function set($key,$value){
        return self::request("SET {$key} {$value}");
    }

    public static function request($string){
        $client = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
        socket_connect($client,self::$host,self::$port);
        socket_write($client,$string);

        $read = socket_read($client,1024);
        socket_close($client);
        return $read;
    }
}

Client::$host = '127.0.0.1';
Client::$port = 4481;

echo Client::set('test','test123'),PHP_EOL;
echo Client::get('test'),PHP_EOL;
echo Client::get('foo'),PHP_EOL;